package com.ynny.controller;


import com.ynny.servic.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 默认情况
 * return 的字符串 找的是视图(View) 页面的(文件) 名称
 * 如何返回一个普通的字符串
 */
@RestController
@RequestMapping("/user")
public class UserControllerImpl {


    @Autowired
    private UserService userService;
    @PostMapping("/login")
    public ResponseEntity<String> login(@RequestParam String number,
                                        @RequestParam String password
                                        ) {
        boolean result = userService.login(number, password);
        if (result ) {
            return ResponseEntity.status(200).body("登录成功");
        } else {
            return ResponseEntity.status(400).body("登录失败");
        }
    }
    @PostMapping("/register")
    public ResponseEntity<String> register(@RequestParam String number,
                                           @RequestParam String password) {
        // 处理注册逻辑
        boolean result = userService.register(number, password);
        if (result) {
            return ResponseEntity.status(200).body("注册成功");
        } else {
            return ResponseEntity.status(400).body("注册失败");
        }
    }

}

